<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of surat_model
 *
 * @author brlnt
 */
class Pencarian_model extends CI_Model {
    //put your code here
    function Pencarian_model() {
        parent::__construct();
        $this->CI = get_instance();
    }

    function getSuratByKodeSurat($kode_surat) {
        $this->db->select('*');
        $this->db->from('surat');
        $this->db->where('kode_surat', $kode_surat);
        // set the result
        return $this->db->get();
    }   
	
	function selectAll($keyword){
	
		$bagianWhere = "";
		if ($keyword['kode_surat'] != null){
			$kode_surat = $keyword['kode_surat'];
			if (empty($bagianWhere))
				{
					$bagianWhere .= " kode_surat = '$kode_surat' ";
				}
		}

		if ($keyword['nama_instansi'] != null){
			$nama_instansi = $keyword['nama_instansi'];
			
			if (empty($bagianWhere))
			{
				$bagianWhere .= " nama_instansi LIKE '%$nama_instansi%' ";
			}
			else
			{
				$bagianWhere .= " AND nama_instansi LIKE '%$nama_instansi%' ";
			}
		}

		 if ($keyword['tanggal_kerjasama'] != null){
			$tanggal_kerjasama = $keyword['tanggal_kerjasama'];
			if (empty($bagianWhere))
			{
				$bagianWhere .= " tanggal_kerjasama LIKE '%$tanggal_kerjasama%' ";
			}
			else
			{
				$bagianWhere .= " AND tanggal_kerjasama LIKE '%$tanggal_kerjasama%' ";
			}
		}

		if ($keyword['masa_berlaku'] != null){
			$masa_berlaku = $keyword['masa_berlaku'];
			if (empty($bagianWhere))
			{
				$bagianWhere .= " masa_berlaku = '%$masa_berlaku%'";
			}else{
				$bagianWhere .= " AND masa_berlaku = '%$masa_berlaku%'";
			}
		}
		
		if ($keyword['unit_terkait']!= null){
			$unit_terkait = $keyword['unit_terkait'];
			if (empty($bagianWhere))
			{
				$bagianWhere .= " unit_terkait = '%$unit_terkait%'";
			}else{
				$bagianWhere .= " AND unit_terkait = '%$unit_terkait%'";
			}
		}
		
		if ($keyword['implementasi']!= null){
			$implementasi = $keyword['implementasi'];
			if (empty($bagianWhere))
			{
				$bagianWhere .= " implementasi = '%$implementasi%'";
			}else{
				$bagianWhere .= " AND implementasi = '%$implementasi%'";
			}
		}
		
		if ($keyword['kerjasama_mengenai']!= null){
			$kerjasama_mengenai = $keyword['kerjasama_mengenai'];
			if (empty($bagianWhere))
			{
				$bagianWhere .= " kerjasama_mengenai = '%$kerjasama_mengenai%'";
			}else{
				$bagianWhere .= " AND kerjasama_mengenai = '%$kerjasama_mengenai%'";
			}
		}
		
		if ($keyword['nomersurat']!= null){
			$nomersurat = $keyword['nomersurat'];
			if (empty($bagianWhere))
			{
				$bagianWhere .= " nomersurat = '%$nomersurat%'";
			}else{
				$bagianWhere .= " AND nomersurat = '%$nomersurat%'";
			} 
		}
		$sql = "SELECT * FROM surat WHERE ".$bagianWhere;
		$query = $this->db->query($sql);
		return $query;
	
	}
	
	
	
	
}

?>
